//
//  BLInfoTestResultVC.m
//  Byelone
//
//  Created by 乔小乔 on 2021/2/5.
//

#import "BLInfoTestResultVC.h"
#import "BLInfoTestController.h"
#import "BLMyController.h"
#import "BLInfoModel.h"
#import "BLLineChatView.h"
@interface BLInfoTestResultVC ()
@property (weak, nonatomic) IBOutlet UIView *viewResult;
@property (weak, nonatomic) IBOutlet UILabel *labelTitle;

@end

@implementation BLInfoTestResultVC

- (void)viewDidLoad {
    [super viewDidLoad];
    if (self.testType == BLTestResultTypeLover) {
        self.navigationItem.title = @"期望对象";
    }else{
        self.navigationItem.title = @"性格测试";
    }
    [self createUI];
    
}

- (void)createUI{
    if (self.arrayResult.count<=0) {
        [[BLHUD shareHud]showtip:@"未获取到测试结果"];
        return;
    }
    NSArray *colors = @[@"#E3E3FC",@"#F3E3FC",@"#DBF0FF",@"#FCE0E0",@"#EAFFDC",@"#DAFFFB"];
    BLLineChatView *chartView = [[BLLineChatView alloc]initWithFrame:CGRectMake(41, 40, BL_WINDOW_WIDTH-82, 164)];
    NSMutableArray *arrayColor = [NSMutableArray new];
    NSMutableArray *arrayPoint = [NSMutableArray new];
    for (int i=0;i<self.arrayResult.count;i++) {
        BLTestResultItem *item = self.arrayResult[i];
        BLChatModel *model = [[BLChatModel alloc]init];
        if (i<colors.count) {
            model.color = [UIColor chColorWithHexString:colors[i]];
        }else{
            model.color = [UIColor chColorWithHexString:colors[0]];
        }
        model.topTitle = item.subLabelName.count>=1?item.subLabelName[0]:@"";
        model.bottomTitle = item.subLabelName.count>=2?item.subLabelName[1]:@"";
        
        [arrayColor addObject:model];
        [arrayPoint addObject:item.score];
    }
    
    chartView.textHeight = 22;
    chartView.textColor = [UIColor chColorWithHexString:@"#555555"];
    chartView.textFont = 13;
    chartView.arrayBjColor = arrayColor;
    chartView.yTotal = 20;
    chartView.differenceValue = 10;
    chartView.itemWidth = 24;
    chartView.lineWidth = 3;
    chartView.pointYArray = @[arrayPoint];
    chartView.arrayLineColor = @[[UIColor chColorWithHexString:@"#999DFF"]];
    [chartView loadView];
    [self.viewResult addSubview:chartView];
    
    self.labelTitle.text = @"经测试您是一个***的人";
}
- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    [self.btnToSelfPage setGradientBackgroundWithColors:@[[UIColor chColorWithHexString:@"#8881FD"],[UIColor chColorWithHexString:@"#6B71F5"]] locations:@[@(0.0f), @(1.0f)]  startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
    [self.btnToMatch setGradientBackgroundWithColors:@[[UIColor chColorWithHexString:@"#AEAAFF"],[UIColor chColorWithHexString:@"#8680FC"]] locations:@[@(0.0f), @(1.0f)]  startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
}

- (IBAction)clickReTest:(id)sender {
//    TODO:还需要在优化
//    if (self.isFromTest) {
//        [self.navigationController popViewControllerAnimated:YES];
//    }else{
        BLInfoTestController *vc = [[BLInfoTestController alloc]init];
        vc.testType = (NSInteger)self.testType;
        [self.navigationController pushViewController:vc animated:YES];
//    }
}
- (IBAction)clickMatch:(id)sender {
//    if (self.isFromTest) {
//        [self.navigationController popViewControllerAnimated:YES];
//    }else{
    
//    TODO:还需要在优化
        BLInfoTestController *vc = [[BLInfoTestController alloc]init];
        vc.testType = BLInfoTestTypeLover;
        [self.navigationController pushViewController:vc animated:YES];
//    }
}

- (IBAction)clickToMy:(id)sender {
    NSArray *array = self.navigationController.viewControllers;
    if (array.count>0) {
        UIViewController *ctr = array[0];
        if ([ctr isKindOfClass:[BLMyController class]]) {
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [self dismissViewControllerAnimated:NO completion:^{
                UINavigationController *nv = [BLTool getCurrentNavigationController];
                nv.tabBarController.selectedIndex = 3;
            }];
        }
    }
    
}

@end
